package c.h.a.k0.a;

import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import c.h.a.m0.o;
import com.liuzh.deviceinfo.tests.TestesActivity;

/* compiled from: BluetoothTestFragment */
public class y extends c.h.a.y.a {
    public ImageView W;
    public TextView X;
    public Button Y;
    public BluetoothAdapter Z;
    public int b0 = 2;
    public View c0;
    public TestesActivity d0;
    public BroadcastReceiver e0 = new b();

    /* compiled from: BluetoothTestFragment */
    public class a extends Thread {
        public void run() {
            try {
                if (y.this.Z.isEnabled()) {
                    y.this.Z.disable();
                } else {
                    y.this.Z.enable();
                }
                c.h.a.m0.p.a.b(new a(this));
                Thread.sleep(2000);
                if (!y.this.m0()) {
                    y yVar;
                    if (y.this.Z.isEnabled()) {
                        yVar = y.this;
                        yVar.b0 = 1;
                        yVar.Z.disable();
                    } else {
                        yVar = y.this;
                        yVar.b0 = 0;
                        yVar.Z.enable();
                    }
                }
            } catch (Exception unused) {
                c.h.a.m0.p.a.b(new b(this));
            }
        }
    }

    /* compiled from: BluetoothTestFragment */
    public class b extends BroadcastReceiver {
        public void onReceive(Context context, Intent intent) {
            y yVar = y.this;
            if (yVar.c0 != null && !yVar.m0()) {
                int intExtra = intent.getIntExtra("android.bluetooth.adapter.extra.STATE", Integer.MIN_VALUE);
                if (intExtra != 4) {
                    switch (intExtra) {
                        case 10:
                            yVar = y.this;
                            if (yVar.b0 == 1) {
                                y.r0(yVar);
                                return;
                            }
                            yVar.W.setImageResource(2131231112);
                            y.this.Y.setVisibility(8);
                            return;
                        case 11:
                            y.this.W.setImageResource(2131231112);
                            y.this.Y.setVisibility(8);
                            y.this.X.setText(2131689636);
                            return;
                        case 12:
                            yVar = y.this;
                            if (yVar.b0 == 0) {
                                y.r0(yVar);
                                return;
                            }
                            yVar.W.setImageResource(2131231112);
                            y.this.Y.setVisibility(8);
                            return;
                        case 13:
                            y.this.W.setImageResource(2131231112);
                            y.this.Y.setVisibility(8);
                            return;
                        default:
                            return;
                    }
                }
                y.this.s0();
            }
        }
    }

    public static void r0(y yVar) {
        yVar.W.setImageResource(2131231114);
        yVar.X.setText(2131690450);
        yVar.Y.setVisibility(0);
        c.b.a.a.a.o(o.b.a, "test_bluetooth", 1);
    }

    public void D(Context context) {
        super.D(context);
        TestesActivity testesActivity = (TestesActivity) context;
        this.d0 = testesActivity;
        testesActivity.setTitle(2131689635);
    }

    public void E(Bundle bundle) {
        super.E(bundle);
        this.d0.registerReceiver(this.e0, new IntentFilter("android.bluetooth.adapter.action.STATE_CHANGED"));
    }

    public View G(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        if (this.c0 == null) {
            View inflate = layoutInflater.inflate(2131493071, viewGroup, false);
            this.c0 = inflate;
            this.W = (ImageView) inflate.findViewById(2131296633);
            this.X = (TextView) this.c0.findViewById(2131296715);
            this.W.setImageResource(2131231112);
            Button button = (Button) this.c0.findViewById(2131296405);
            this.Y = button;
            button.setOnClickListener(new c(this));
            BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
            this.Z = defaultAdapter;
            if (defaultAdapter == null) {
                s0();
                return this.c0;
            }
            new a().start();
        }
        return this.c0;
    }

    public void H() {
        this.E = true;
        if (this.Z != null) {
            BroadcastReceiver broadcastReceiver = this.e0;
            if (broadcastReceiver != null) {
                this.d0.unregisterReceiver(broadcastReceiver);
            }
        }
    }

    public final void s0() {
        this.W.setImageResource(2131231113);
        this.X.setText(2131690449);
        c.b.a.a.a.o(o.b.a, "test_bluetooth", 0);
    }
}
